<?php

/**
 * This is the model class for table "nguoidung".
 *
 * The followings are the available columns in table 'nguoidung':
 * @property integer $Id
 * @property string $Ten
 * @property string $BiDanh
 * @property string $Slogan
 * @property string $DiaChi
 * @property string $SDT
 * @property string $NgaySinh
 * @property string $CMND
 * @property string $CoQuan
 * @property string $Email
 * @property string $NgayDangKy
 * @property string $TenDangNhap
 * @property string $MatKhau
 * @property integer $UyTin
 * @property string $Avatar
 * @property integer $TrangThai
 *
 * The followings are the available model relations:
 * @property Banbe[] $banbes
 * @property Banbe[] $banbes1
 * @property Nhom[] $nhoms
 * @property Danhmuc[] $danhmucs
 * @property Linhvuc[] $linhvucs
 * @property Ytuong[] $ytuongs
 */
class NguoiDung extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'nguoidung';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('Ten, TenDangNhap, MatKhau', 'required'),
			array('UyTin, TrangThai', 'numerical', 'integerOnly'=>true),
			array('Ten, BiDanh, CoQuan, Email', 'length', 'max'=>100),
			array('Slogan, DiaChi', 'length', 'max'=>200),
			array('SDT, TenDangNhap, MatKhau', 'length', 'max'=>20),
			array('CMND', 'length', 'max'=>15),
			array('Avatar', 'length', 'max'=>10),
			array('NgaySinh, NgayDangKy', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('Id, Ten, BiDanh, Slogan, DiaChi, SDT, NgaySinh, CMND, CoQuan, Email, NgayDangKy, TenDangNhap, MatKhau, UyTin, Avatar, TrangThai', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'banbes' => array(self::HAS_MANY, 'Banbe', 'NguoiDungId1'),
			'banbes1' => array(self::HAS_MANY, 'Banbe', 'NguoiDungId2'),
			'nhoms' => array(self::MANY_MANY, 'Nhom', 'thanhviennhom(NguoiDungId, NhomId)'),
			'danhmucs' => array(self::MANY_MANY, 'Danhmuc', 'theodoidanhmuc(NguoiDungId, DanhMucId)'),
			'linhvucs' => array(self::MANY_MANY, 'Linhvuc', 'theodoilinhvuc(NguoiDungId, LinhVucId)'),
			'ytuongs' => array(self::MANY_MANY, 'Ytuong', 'theodoiytuong(NguoiDungId, YTuongId)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'Id' => 'Mã người dùng',
			'Ten' => 'Tên người dùng',
			'BiDanh' => 'Bí Danh',
			'Slogan' => 'Câu nói yêu thích',
			'DiaChi' => 'Địa chỉ',
			'SDT' => 'Số điện thoại',
			'NgaySinh' => 'Ngày sinh',
			'CMND' => 'CMND',
			'CoQuan' => 'Cơ Quan',
			'Email' => 'Email',
			'NgayDangKy' => 'Ngày đăng ký',
			'TenDangNhap' => 'Tên đăng nhập',
			'MatKhau' => 'Mật khẩu',
			'UyTin' => 'Uy tín người dùng',
			'Avatar' => 'Avatar',
			'TrangThai' => 'Trang Thai',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('Id',$this->Id);
		$criteria->compare('Ten',$this->Ten,true);
		$criteria->compare('BiDanh',$this->BiDanh,true);
		$criteria->compare('Slogan',$this->Slogan,true);
		$criteria->compare('DiaChi',$this->DiaChi,true);
		$criteria->compare('SDT',$this->SDT,true);
		$criteria->compare('NgaySinh',$this->NgaySinh,true);
		$criteria->compare('CMND',$this->CMND,true);
		$criteria->compare('CoQuan',$this->CoQuan,true);
		$criteria->compare('Email',$this->Email,true);
		$criteria->compare('NgayDangKy',$this->NgayDangKy,true);
		$criteria->compare('TenDangNhap',$this->TenDangNhap,true);
		$criteria->compare('MatKhau',$this->MatKhau,true);
		$criteria->compare('UyTin',$this->UyTin);
		$criteria->compare('Avatar',$this->Avatar,true);
		$criteria->compare('TrangThai',$this->TrangThai);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return NguoiDung the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
